package com.yitiao.simple.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import lombok.SneakyThrows;

import java.net.InetSocketAddress;

public class NettyHttpServer {

    @SneakyThrows
    public static void main(String[] args) {
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);
        EventLoopGroup workerGroup = new NioEventLoopGroup();

        ServerBootstrap server = new ServerBootstrap();
        server.group(bossGroup,workerGroup)
                .channel(NioServerSocketChannel.class)
                .childHandler(new HttpServerHandlerInitializer());

        ChannelFuture channelFuture = server.bind(6378).sync();
        channelFuture.channel().closeFuture().sync();

        System.out.println("quit...");
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();
    }
}
